<!--title-->
<div class="mnav1">
	<div class="m_nav">
		<div class="nav_left">
			<em class="home_icon"><?=$this->sys_name?></em><span>&nbsp;&gt;&nbsp;</span><font><?=$this->title?></font>
		</div>
	</div>
</div>

<div class="content-table">
<div class="content-table-title"><?=$this->title?></div>
<br />
<?php if($this->msg):?>
<div class="replace"><?=$this->msg?></div>
<br />
<?php endif;?>
<form action="/accounting/index" name="form1" method="GET">
计划回款日期：&nbsp;&nbsp;<a href="?period_id=0&<?=$this->params_string2?>" <?php if(!$this->period_id):?>style="color: red; font-weight: bold"<?php endif;?>>全部</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?period_id=1&<?=$this->params_string2?>" <?php if(1==$this->period_id):?>style="color: red; font-weight: bold"<?php endif;?>>今天</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?period_id=2&<?=$this->params_string2?>" <?php if(2==$this->period_id):?>style="color: red; font-weight: bold"<?php endif;?>>明天</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?period_id=3&<?=$this->params_string2?>" <?php if(3==$this->period_id):?>style="color: red; font-weight: bold"<?php endif;?>>本周</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?period_id=4&<?=$this->params_string2?>" <?php if(4==$this->period_id):?>style="color: red; font-weight: bold"<?php endif;?>>下周</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?period_id=5&<?=$this->params_string2?>" <?php if(5==$this->period_id):?>style="color: red; font-weight: bold"<?php endif;?>>本月</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?period_id=6&<?=$this->params_string2?>" <?php if(6==$this->period_id):?>style="color: red; font-weight: bold"<?php endif;?>>下月</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;自定义时间段&nbsp;&nbsp;<input type="text" name="date_start" id="date_start" value="<?=$this->date_start?>" style="width: 100px" autocomplete="off"> ~ <input type="text" name="date_end" id="date_end" value="<?=$this->date_end?>" style="width: 100px" autocomplete="off">
<br />
实际回款日期：&nbsp;&nbsp;<a href="?period_id_2=0&<?=$this->params_string5?>" <?php if(!$this->period_id_2):?>style="color: red; font-weight: bold"<?php endif;?>>全部</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?period_id_2=1&<?=$this->params_string5?>" <?php if(1==$this->period_id_2):?>style="color: red; font-weight: bold"<?php endif;?>>今天</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?period_id_2=2&<?=$this->params_string5?>" <?php if(2==$this->period_id_2):?>style="color: red; font-weight: bold"<?php endif;?>>昨天</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?period_id_2=3&<?=$this->params_string5?>" <?php if(3==$this->period_id_2):?>style="color: red; font-weight: bold"<?php endif;?>>本周</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?period_id_2=4&<?=$this->params_string5?>" <?php if(4==$this->period_id_2):?>style="color: red; font-weight: bold"<?php endif;?>>上周</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?period_id_2=5&<?=$this->params_string5?>" <?php if(5==$this->period_id_2):?>style="color: red; font-weight: bold"<?php endif;?>>本月</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?period_id_2=6&<?=$this->params_string5?>" <?php if(6==$this->period_id_2):?>style="color: red; font-weight: bold"<?php endif;?>>上月</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?period_id_2=7&<?=$this->params_string5?>" <?php if(7==$this->period_id_2):?>style="color: red; font-weight: bold"<?php endif;?>>今年</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;自定义时间段&nbsp;&nbsp;<input type="text" name="date_start_2" id="date_start_2" value="<?=$this->date_start_2?>" style="width: 100px" autocomplete="off"> ~ <input type="text" name="date_end_2" id="date_end_2" value="<?=$this->date_end_2?>" style="width: 100px" autocomplete="off">
<br /><br />
回款状态：&nbsp;&nbsp;<a href="?status_type=0&<?=$this->params_string3?>" <?php if(!$this->status_type):?>style="color: red; font-weight: bold"<?php endif;?>>全部</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?status_type=1&<?=$this->params_string3?>" <?php if(1==$this->status_type):?>style="color: red; font-weight: bold"<?php endif;?>>未回款</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?status_type=2&<?=$this->params_string3?>" <?php if(2==$this->status_type):?>style="color: red; font-weight: bold"<?php endif;?>>已回款</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?status_type=3&<?=$this->params_string3?>" <?php if(3==$this->status_type):?>style="color: red; font-weight: bold"<?php endif;?>>逾期未回款</a>
<br /><br />
产品：&nbsp;&nbsp;<a href="?product_id=0&<?=$this->params_string4?>" <?php if(!$this->product_id):?>style="color: red; font-weight: bold"<?php endif;?>>全部</a>
	<?php foreach($this->products as $product_id => $product_name):?>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="?product_id=<?=$product_id?>&<?=$this->params_string4?>" <?php if($product_id==$this->product_id):?>style="color: red; font-weight: bold"<?php endif;?>><?=$product_name?></a>
	<?php endforeach;?>
<br /><br />
<?php if("LEVEL-1" != $_SESSION['identity']['level']):?>
销售：<select name="sales_emp_id">
		<option value="">不限</option>
		<?php if(!empty($this->sales)):?>
		<?php foreach($this->sales as $sales_emp_id => $sales_name):?>
		<?php if($sales_name):?>
		<option value="<?=$sales_emp_id?>"<?php if($sales_emp_id==$this->sales_emp_id):?> selected="selected"<?php endif;?>><?=$sales_name?></option>
		<?php endif;?>
		<?php endforeach;?>
		<?php endif;?>
	</select>
&nbsp;&nbsp;&nbsp;&nbsp;
<?php endif;?>
关键字：<input type="text" name="keyword" <?php if($this->keyword){echo "value='".$this->keyword."'";}?> />
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" class="button" value="搜索" />
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" class="button-cancle" value="清空搜索条件" onclick="location.href='?';" />
&nbsp;&nbsp;&nbsp;&nbsp;
<font color="red"><b>当前搜索记录数: <?=$this->data['ct']?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;当前金额: <?=number_format($this->data['sm'],2,".",",")?>元</b></font>
</form>
<br />
<br />
<table>
  <tr>
	<th>计划回款日期</th>
    <th>计划回款金额</th>
    <th>合同号</th>
    <th>客户</th>
    <th>产品</th>
    <th>销售</th>
    <th>回款状态</th>
    <th>实际回款日期</th>
    <th>逾期天数</th>
    <th>操作</th>
    <th>备注</th>
  </tr>
  <?php
	$today = date("Y-m-d");
	$today_start = mktime(0,0,0,substr($today,5,2),substr($today,8,2),substr($today,0,4));
	$today_end = mktime(23,59,59,substr($today,5,2),substr($today,8,2),substr($today,0,4));
  ?>
  <?php $data = $this->data['current_page_info'];?>
  <?php foreach($data["client_name"] as $id => $something):?>
  <?php
  $expired_day = "";
  $row_ts = mktime(0,0,0,substr($data["plan_date"][$id],5,2),substr($data["plan_date"][$id],8,2),substr($data["plan_date"][$id],0,4));
  
  if($row_ts < $today_start && !$data["status"][$id])
  {
	  $color = "red";
	  
	  $expired_day = intval(($today_start - $row_ts) / (3600 * 24));
	  
  }elseif($row_ts >= $today_start && $row_ts <= $today_end && !$data["status"][$id])
  {
	  $color = "green";
  }else{
	  $color = "black";
  }
  ?>
  <tr>
	<td style="color: <?=$color?>"><?=$data["plan_date"][$id]?></td>
	<td><?=number_format($data["plan_value"][$id],2,".",",")?></td>
	<td><?=$data["contract_sid"][$id]?></td>
    <td><?=$data["client_name"][$id]?></td>
    <td><?=$data["product_name"][$id]?></td>
	<td><?=$data["sales_emp_name"][$id]?></td>
	<td style="color: <?=$color?>"><?=$data["status"][$id]?"已回款":"未回款"?></td>
	<td><?=$data["confirmed_time"][$id]?></td>
	<td style="color: <?=$color?>"><?=$expired_day?></td>
    <td><button onclick="window.open('/contracts/view-contract/contract_id/<?=$data["contract_id"][$id]?>')">查看/编辑</button></td>
	<td><?=$data["tips"][$id]?></td>
  </tr>
  <?php endforeach;?>
</table>
</div>
<br /><br />
<div align="right"><?=$this->pagination?></div>
<br /><br /><br />

<script>
$(function() {
	$( "#date_start" ).datepicker({ dateFormat: 'yy-mm-dd'});
});
$(function() {
	$( "#date_end" ).datepicker({ dateFormat: 'yy-mm-dd'});
});
$(function() {
	$( "#date_start_2" ).datepicker({ dateFormat: 'yy-mm-dd'});
});
$(function() {
	$( "#date_end_2" ).datepicker({ dateFormat: 'yy-mm-dd'});
});
</script>